# frozen_string_literal: true

class CreateRuleConditions < ActiveRecord::Migration[6.0]
  def change
    create_table :rule_conditions do |t|
      t.integer :general_rule_id, null: false,  limit: 8
      t.integer :ordinal,         null: false,  limit: 4
      t.string  :lvalue,          null: false,  limit: 255
      t.string  :operator,        null: false,  limit: 255
      t.string  :rvalue_type,     null: false,  limit: 64
      t.string  :rvalue,          null: true,   limit: 255
      t.timestamps                null: false
    end

    add_index :rule_conditions, %i[ordinal general_rule_id], unique: true
    add_foreign_key :rule_conditions, :rule_entities, column: :general_rule_id
  end
end
